#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;

int n, m;
ll h[N], v[N], s[N];
int f[N], a[N], c[N];
int rt[N], dep[N], ans[N], cnt[N];
int lc[N], rc[N], dis[N];
ll val[N], k[N], d[N];

void addtag(ll x, ll y, ll p) {
  if (!p) return;
  val[p] = val[p] * x + y;
  k[p] = k[p] * x;
  d[p] = d[p] * x + y;
}
void pushdown(ll p) {
  if (k[p] != 1 || d[p] != 0) {
    addtag(k[p], d[p], lc[p]);
    addtag(k[p], d[p], rc[p]);
    k[p] = 1, d[p] = 0;
  }
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  if (val[x] == val[y] ? x > y : val[x] > val[y]) swap(x, y);
  pushdown(x);
  rc[x] = merge(rc[x], y);
  if (dis[lc[x]] < dis[rc[x]]) swap(lc[x], rc[x]);
  dis[x] = dis[lc[x]] + 1;
  return x;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  dis[0] = -1;
  cin >> n >> m;
  rep(i, 1, n) cin >> h[i];
  rep(i, 2, n) cin >> f[i] >> a[i] >> v[i];
  rep(i, 1, m) cin >> s[i] >> c[i];
  // build dep
  rep(i, 1, n) dep[i] = dep[f[i]] + 1;
  // init ans
  rep(i, 1, m) ans[i] = dep[c[i]];
  // init val
  rep(i, 1, m) val[i] = s[i], k[i] = 1, d[i] = 0;
  // knight start from c[i]
  rep(i, 1, m) rt[c[i]] = merge(rt[c[i]], i);
  // knight move up
  per(i, n, 1) {
    while (rt[i] && val[rt[i]] < h[i]) {
      cnt[i]++;
      pushdown(rt[i]);
      // update ans for knight at rt[i]
      ans[rt[i]] = dep[c[rt[i]]] - dep[i];
      rt[i] = merge(lc[rt[i]], rc[rt[i]]);
    }
    if (a[i] == 0)
      addtag(1, v[i], rt[i]);
    else
      addtag(v[i], 0, rt[i]);
    rt[f[i]] = merge(rt[f[i]], rt[i]);
  }
  rep(i, 1, n) cout << cnt[i] << endl;
  rep(i, 1, m) cout << ans[i] << endl;
  return 0;
}